package controller

import (
	"github.com/gin-gonic/gin"
	"sport_booking/models"
	"sport_booking/utils/message"
)

/*
获取第一级省市
*/
func GetOneProvince(c *gin.Context) {
	var geos []models.Geo
	var status int
	geos, status = models.GetOneProvince()
	if status != message.SUCCESS {
		message.SendMsg(c, message.ErrorGeoGetOneProvince)
		return
	}
	message.SendMsg(c, message.SUCCESS, geos)
}

/*
获取其他城市
*/
func GetOtherCity(c *gin.Context) {
	var geo models.Geo
	var geos []models.Geo
	var status int
	err := c.ShouldBindJSON(&geo)
	if err != nil {
		message.SendMsg(c, message.ErrorBindData)
		return
	}
	if geo.Level > 3 || geo.Level < 1 || geo.AreaCode == 0 {
		message.SendMsg(c, message.ErrorDataFormat)
		return
	}
	geos, status = models.GetOtherCity(&geo)
	if status != message.SUCCESS {
		message.SendMsg(c, message.ErrorGeoGetOtherCity)
		return
	}
	message.SendMsg(c, message.SUCCESS, geos)
}
